package com.ruoyi.web.controller.finance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.PaymentSlips;
import com.ruoyi.finance.service.IPaymentSlipsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 付款单Controller
 * 
 * @author ruoyi
 * @date 2023-11-29
 */
@RestController
@RequestMapping("/finance/PaymentSlips")
public class PaymentSlipsController extends BaseController
{
    @Autowired
    private IPaymentSlipsService paymentSlipsService;

    /**
     * 查询付款单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaymentSlips paymentSlips)
    {
        startPage();
        List<PaymentSlips> list = paymentSlipsService.selectPaymentSlipsList(paymentSlips);
        return getDataTable(list);
    }

    /**
     * 导出付款单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:export')")
    @Log(title = "付款单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaymentSlips paymentSlips)
    {
        List<PaymentSlips> list = paymentSlipsService.selectPaymentSlipsList(paymentSlips);
        ExcelUtil<PaymentSlips> util = new ExcelUtil<PaymentSlips>(PaymentSlips.class);
        util.exportExcel(response, list, "付款单数据");
    }

    /**
     * 获取付款单详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        return success(paymentSlipsService.selectPaymentSlipsByPaymentId(paymentId));
    }

    /**
     * 新增付款单
     */
    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:add')")
    @Log(title = "付款单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaymentSlips paymentSlips)
    {
        return toAjax(paymentSlipsService.insertPaymentSlips(paymentSlips));
    }

    /**
     * 修改付款单
     */
    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:edit')")
    @Log(title = "付款单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaymentSlips paymentSlips)
    {
        return toAjax(paymentSlipsService.updatePaymentSlips(paymentSlips));
    }

    /**
     * 删除付款单
     */
    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:remove')")
    @Log(title = "付款单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(paymentSlipsService.deletePaymentSlipsByPaymentIds(paymentIds));
    }

    /**
     * 核准功能
     * @param paymentIds
     * @param flay
     * @return
     */
    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:paymentApplicant')")
    @PutMapping("/updatePaymentApplicant/{paymentIds}/{flay}")
    public AjaxResult updatePaymentApplicant(@PathVariable Long[] paymentIds,@PathVariable boolean flay){
        return toAjax(paymentSlipsService.updatePaymentApplicant(paymentIds,flay,getNickname()));
    }

    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:paymentApplicant')")
    @GetMapping("/selectPaymentApplicantByPaymentId/{paymentIds}")
    public AjaxResult selectPaymentApplicantByPaymentId(@PathVariable Long[] paymentIds){
        return success(paymentSlipsService.selectPaymentApplicantByPaymentId(paymentIds));
    }


    @PreAuthorize("@ss.hasPermi('finance:PaymentSlips:posting')")
    @PutMapping("/updatePostingApplicant/{paymentIds}")
    public AjaxResult updatePostingApplicant(@PathVariable Long[] paymentIds){
        return toAjax(paymentSlipsService.updatePostingApplicant(paymentIds,getNickname()));
    }

}
